<?php

/**
* @author trungdt
* @since Feb 2011
* 
*/
/**
* Change logs
* Feb 11, 2011 - trungdt - Add views FeatureTab, so, we must add configure that LinkList module will automatic remove html of body field
* Sep 22, 2011 - trungdt - Add No_search support
* 
*                ALTER TABLE `ag_linklistmodule_config` ADD `remove_body_html` INT( 1 ) NOT NULL DEFAULT '0' COMMENT '=0: No remove, =1: remove'
* 
* Sep 6, 2011 - trungdt - Add config: show Default view when in Administrator mode or not
* 
*    
*/

class linklistmodule_config {
	function form($object) {
		if (!defined('SYS_FORMS')) require_once(BASE.'subsystems/forms.php');
		exponent_forms_initialize();
		$form = new form();
		if (!isset($object->id)) {
			$object->sort = 'asc_name';
			$object->remove_body_html=0;
			$object->listing_type=0;
			$object->first_link_as_title=0;
			$object->no_search=0;
            $object->item_width=100;
            $object->name_multiline=0;
            $object->show_date=0;
            $object->force_title="";
            $object->item_per_page=20;
            $object->item_at_firstpage=0;
			$object->force_top_sentence=0;
		} else {
			switch ($object->orderhow) {
				case 0: // ascending
					$object->sort = 'asc_'.$object->orderby;
					break;
				case 1: // descending
					$object->sort = 'desc_'.$object->orderby;
					break;
				case 2: // random
					$object->sort = 'random_';
					break;
				case 3: // order specified by arrows
					$object->sort = 'rank_';
					break;
                case 4: // order specified by arrows
                    $object->sort = 'rankv_';
                    break;
				default:
					$object->sort = 'asc_name';
					break;
			}
			$form->meta('id',$object->id);
		}

		$order_options = array(
			'random_'=>'Randomly',
			'asc_name'=>'Alphabetical By Name',
			'desc_name'=>'Reverse Alphabetical By Name',
            'rank_'=>'By rank order',
			'rankv_'=>'By rank order reversed',
		);
        
        $form->register('force_title','Force use this title',new textcontrol($object->force_title));
        
        $listing_type = array(
            0=>'Normal listing',
            1=>'Staff listing - Our team',
        );
        
        
        $form->register('listing_type','Module Listing Style',new dropdowncontrol($object->listing_type,$listing_type));
        
		$form->register('orderby','Sorting',new dropdowncontrol($object->sort,$order_options));
		$form->register('remove_body_html','Remove HTML on body content&nbsp;',new checkboxcontrol($object->remove_body_html));
		$form->register('first_link_as_title','First link as title&nbsp;',new checkboxcontrol($object->first_link_as_title));
		// Sep 22, 2011 - trungdt - Add no search
        $form->register('item_width','Image Thumb Width',new textcontrol($object->item_width));
        $form->register('item_per_page','Item per page - Pagination',new textcontrol($object->item_per_page));
        $form->register('item_at_firstpage','Item at first page (enter 0 for unlimit)',new textcontrol($object->item_at_firstpage));
        $form->register('no_search','No Serach Generate&nbsp;',new checkboxcontrol($object->no_search));
        $form->register('show_date','Show post date when view detail',new checkboxcontrol($object->show_date));
		$form->register('name_multiline','Short description&nbsp;',new checkboxcontrol($object->name_multiline));
        
        $form->register('force_top_sentence','Force top Sentence same with this module&nbsp;',new checkboxcontrol($object->force_top_sentence));
        
		$form->register('submit','',new buttongroupcontrol('Save','','Cancel'));
		return $form;
	}

	function update($values,$object) {
		$toks = explode('_',$values['orderby']);
		switch ($toks[0]) {
			case 'rank':
				$object->orderhow = 3;
				break;
            case 'rankv':
                $object->orderhow = 4;
                break;
			case 'random':
				$object->orderhow = 2;
				break;
			case 'asc':
				$object->orderhow = 0;
				break;
			case 'desc':
				$object->orderhow = 1;
				break;
		}
		
        $object->item_width = intval($values['item_width']);
        $object->item_per_page = intval($values['item_per_page']);
		$object->item_at_firstpage = intval($values['item_at_firstpage']);
        $object->force_title = trim($values['force_title']);
		
		$object->orderby = $toks[1];
		if (isset($values['remove_body_html'])){
			$object->remove_body_html=1;
		}
		else
		{
			$object->remove_body_html=0;
		}
		
        $object->listing_type = intval($values['listing_type']);
		
		if (isset($values['first_link_as_title'])){
			$object->first_link_as_title=1;
		}
		else
		{
			$object->first_link_as_title=0;
		}
		
		if (isset($values['no_search'])){
            $object->no_search=1;
        }
        else
        {
            $object->no_search=0;
        }
        
        if (isset($values['name_multiline'])){
            $object->name_multiline=1;
        }
        else
        {
            $object->name_multiline=0;
        }
        
        if (isset($values['show_date'])){
            $object->show_date=1;
        }
        else
        {
            $object->show_date=0;
        }
        
        if (isset($values['force_top_sentence'])){
			$object->force_top_sentence=1;
		}
		else
		{
			$object->force_top_sentence=0;
		}
		
		return $object;
	}
}

?>